package uk.org.landeg.euler.problems;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;
import uk.org.landeg.euler.problems.lib.NumbersLib;

public class Problem004 extends AbstractProblem{
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem004());
		launcher.solve();
	}
	
	@Override
	public String getDescription() {
		return "Find the largest palindrome made from the product of two 3-digit numbers";
	}

	@Override
	public Integer getProblemNumber() {
		return 4;
	}

	@Override
	public Object solve() {
		notes.add("Brute force for 3 digit numbers above 800");
		long max = 0, current;;
		for (int n1 = 800 ; n1 < 1000 ; n1++) {
			for (int n2 = 800 ; n2 < n1 ; n2++) {
				current = n1 * n2;
				if (NumbersLib.isPalindrome(current)) {
					notes.add(String.format ("%d * %d = %d",n1,n2,current));
					max = (current > max) ? current : max;
				}
			}
		}
		notes.add("Largest found is " + max + " : suggesting this is correct answer");
		return max;
	}
}
